﻿using Bll;
using Dao;
using Microsoft.AspNetCore.Mvc;
using ShareCode.Entity;

namespace ApiApp.Controllers
{
    /// <summary>
    /// 300<SerialNumber<400
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class BaseTreeController<T> : BaseContainTitleController<T> where T : BaseTreeEntity, new()
    {
        protected override BaseTreeBll<T>? Bll => (BaseTreeBll<T>?)base.Bll;


        [HttpPost("GetTreeRoot/{id}")]
        public async virtual Task<JsonResult> GetTreeRootAsync( int id)
        {
            return await OkkAsync(Bll!.GetTreeRootAsync(id));
        }

        [HttpPost("GetTreeParentIds/{id}")]
        public async virtual Task<JsonResult> GetTreeParentIds(int id)
        {
            return await OkkAsync(Bll!.GetTreeParentIds(id));
        }

        [HttpPost("TreeInsertSon")]
        public async virtual Task<JsonResult> TreeInsertSon([FromBody] T entity)
        {
            return await OkkAsync(Bll!.TreeInsertSon(entity));
        }

        [HttpPost("TreeInsertBefore/{id}")]
        public async virtual Task<JsonResult> TreeInsertBefore([FromBody] T entity, int id)
        {
            return await OkkAsync(Bll!.TreeInsertBefore(entity, id));
        }

        [HttpPost("TreeInsertAfter/{id}")]
        public async virtual Task<JsonResult> TreeInsertAfter([FromBody] T entity, int id)
        {
            return await OkkAsync(Bll!.TreeInsertAfter(entity, id));
        }


    }
}
